app.controller("baseController",function($scope) {
    $scope.selectedIds=[];// 存放所 勾选的Id
    $scope.updateSelection=function ($event,id) {

        //$event.target.checked 事件冒泡
        if($event.target.checked){
            //true 勾选
            $scope.selectedIds.push(id);
        }
        else {
            //false 未勾选
            var indexOf = $scope.selectedIds.indexOf(id);
            $scope.selectedIds.splice(index,1);
        }

    }
    $scope.reloadList = function(){
        $scope.search($scope.pageModel.currentPage,$scope.pageModel.itemsPerPage);

    }
    $scope.pageModel = {
        currentPage: 1,
        totalItems: 50,
        itemsPerPage: 10,
        perPageOptions: [5, 10, 15, 40, 50],
        onChange: function(){
            $scope.reloadList();
        }
    }

    //json 转化字符串类型
    $scope.jsonToStr=function (str,keyName) {
        var attrArray=JSON.parse(str);
        var resultStr="";
        for(var i=0;i<attrArray.length;i++){

            if(i==0)
            { resultStr +=attrArray[i][keyName]}
            else{

                resultStr +=","+attrArray[i][keyName]
            }

        }

        return resultStr;

    }

    $scope.searchObjectByKey=function(items,key,text){


        for(var i=0;i<items.length;i++){

            if(items[i].attributeName==text){
                //证明之前有添加过
                return items[i];
            }
        }
        return null;
    }
});